package com.lh.singleton.type2;


//无参构造
public class Singleton1 {
	public static void main(String[] args) {

		Singleton instance = Singleton.getInstance();

		instance.show();
	}
}

class Singleton {


	// 1.构造器私有化，外部能new
	private Singleton() {

	}

	// 本类内部创建对象实例
	private final static Singleton instance;

	//静态代码块
	static {
		instance = new Singleton();
	}

	// 提供一个公共的静态方法，返回实例对象
	public static Singleton getInstance() {

		return instance;
	}

	public void show() {
		System.out.println("测试一下");
	}
}